import sys
import time
import datetime  

sys.path.append("..")
from tqdm import tqdm

from utils import save_obj

# from llm_vllm_data import industry_infos

from OnlineLLM import (
    Yi,
    wenxin,
    )

from llm_vllm_data import remain_text


res = []

err = 0

remain_text = list(remain_text) # [:600]

try:
    for item in tqdm(remain_text):
        answer = wenxin.send_req(item)
        # answer = Yi.send_req(item)
        print(answer.get("result", "None"))
        if "error_code" in answer:
            err += 1
            print(answer["error_code"])
            if err == 10:
                break
            time.sleep(1)
        res.append([item, answer])
        time.sleep(0.5)
except Exception as e:
    print(e)
    

# 获取当前时间  
now = datetime.datetime.now()  
formatted_now = now.strftime('%Y-%m-%d_%H-%M-%S')  
filename = f'objs/online_infer/online_llm_{formatted_now}.pkl'
save_obj(res, filename)
# nohup python online_infer.py > online_infer_res.log 2>&1 &